package com.example.cqcet_demo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.cqcet_demo.R;
import com.example.cqcet_demo.bean.Consume;

import java.util.List;

/**
 * Created by Mr.z on 2017/6/18.
 */

public class MyListViewQueryAdapter extends BaseAdapter {

    private List<Consume> consumes;
    private Context context;

    public MyListViewQueryAdapter(Context context,List consumes){
        this.context = context;
        this.consumes = consumes;
}

    @Override
    public int getCount() {
        return consumes.size();
    }

    @Override
    public Object getItem(int position) {
        return consumes.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if(convertView==null){
            convertView = View.inflate(context, R.layout.consumption_item,null);
            viewHoder = new ViewHoder();
            viewHoder.tv_address = (TextView)convertView.findViewById(R.id.tv_address);
            viewHoder.tv_price = (TextView)convertView.findViewById(R.id.tv_price);
            viewHoder.tv_date = (TextView)convertView.findViewById(R.id.tv_date);
            viewHoder.tv_balance = (TextView)convertView.findViewById(R.id.tv_balance);
            convertView.setTag(viewHoder);
        }else{
            viewHoder = (ViewHoder) convertView.getTag();
        }
        Consume cos = consumes.get(position);
        viewHoder.tv_address.setText(cos.getAddress());
        viewHoder.tv_price.setText(cos.getPrice());
        viewHoder.tv_date.setText(cos.getDate());
        viewHoder.tv_balance.setText(cos.getBalance());

        return convertView;
    }
    static class ViewHoder{
        TextView tv_address;
        TextView tv_price;
        TextView tv_date;
        TextView tv_balance;
    }
}
